package com.baize.minespace.controller;


import com.baize.minespace.pojo.PostContent;
import com.baize.minespace.service.PostContentService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 文章内容表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/post-content")
public class PostContentController {
    @Autowired
    private PostContentService postContentService;

    @ApiModelProperty("新增文章内容表")
    @ApiOperation(value = "新增文章内容表", notes = "新增文章内容表")
    @PostMapping("add")
    public Result<Boolean> addPostContent(@RequestBody PostContent postContent){
        return Result.success(postContentService.save(postContent));
    }

    @ApiModelProperty("删除文章内容表")
    @ApiOperation(value = "删除文章内容表", notes = "删除文章内容表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deletePostContent(@PathVariable(value = "id") Integer id) {
        return Result.success(postContentService.removeById(id));
    }

    @ApiModelProperty("修改文章内容表")
    @ApiOperation(value = "修改文章内容表", notes = "修改文章内容表")
    @PostMapping("update")
    public Result<Boolean> updatePostContent(@RequestBody PostContent postContent) {
        return Result.success(postContentService.updateById(postContent));
    }

    @ApiModelProperty("查询文章内容表")
    @GetMapping("select/{id}")
    public Result<PostContent> selectPostContent(@PathVariable(value = "id") Integer id) {
        return Result.success(postContentService.getById(id));
    }

    @ApiModelProperty("分页查询文章内容表")
    @ApiOperation(value = "分页查询文章内容表", notes = "分页查询文章内容表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<PostContent>> selectPostContentPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody PostContent postContent
    ) {
        return postContentService.selectPostContentPage(rows, page, postContent);
    }
}
